/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */

typedef struct ListNode ListNode;

ListNode* removeDuplicateNodes(ListNode* head)
{
    if (!head)
        return head;

    bool arr[20010] = { false };
    ListNode* pcur = head;
    ListNode* pre = NULL;

    while (pcur)
    {
        if (arr[pcur->val])
        {
            pre->next = pcur->next;
            pcur = pre->next;
        }
        else
        {
            arr[pcur->val] = true;
            pre = pcur;
            pcur = pcur->next;
        }
    }

    return head;
}